package com.lwq.im.chartdemo.bean;

import com.lwq.im.chartdemo.constants.Constants;
import com.lwq.im.chartdemo.endecode.MessageProto;
import lombok.Data;

import java.io.Serializable;

@Data
public class Message implements IMessage, Serializable {
    private static final long serialVersionUID = 1L;


    /**
     * 发消息人
     */
    private String from;

    /**
     * 接收消息人
     */
    private String to;

    /**
     * 消息时间
     */
    private Long timestamp;

    /**
     * 消息内容
     */
    private String content;


    @Override
    public byte[] getBody() {
        MessageProto.Message message = MessageProto.Message.newBuilder()
                .setFrom(getFrom())
                .setTo(getTo())
                .setTimestamp(getTimestamp())
                .setContent(getContent())
                .build();
        return message.toByteArray();
    }

    @Override
    public byte getMsgType() {
        return Constants.MsgType.MESSAGE_TYPE;
    }
}
